package com.qianyu.project.mapper.provider.smj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface smjApplyDao {
    //添加进度款申报
    @Insert("insert into apply_progress_payment(apply_date,p_id, ctr_id, company_id, payment_name, contract_amount, penalty, withhold, settle_type, agree_amount, agree_upper, handler_id, update_user, settle_comment, attach_ids,update_date,id)" +
            "value(#{apply_date},#{p_id},#{ctr_id},#{company_id},#{payment_name},#{contract_amount},#{penalty},#{withhold},#{settle_type},#{agree_amount},#{agree_upper},#{handler_id},#{update_user},#{settle_comment},#{attach_ids},#{update_date},#{id})")
    void AddApply(String apply_date, String p_id, String ctr_id, String company_id, String payment_name, String contract_amount, String penalty, String withhold, String settle_type, String agree_amount, String agree_upper, String handler_id, String update_user, String settle_comment, String attach_ids, String update_date, String id);

    //添加进度款工作量清单
    @Insert("insert into apply_work_list values(null,#{apply_id},#{work_content},#{work_count},#{unit},#{unit_price},#{sum_price},#{snumber},#{hnumber},#{comment})")
    void worklist(String apply_id, String work_content, String work_count, String unit, String unit_price, Integer sum_price, String snumber, String hnumber, String comment);

    //创建审批流程
    @Update("update apply_progress_payment set approve_status =#{approve_status} where id=#{id}")
    void UpdateApproveStatus(int approve_status, String id);

    //查询进度款列表
    @SelectProvider(type = smjApplyProvider.class ,method = "listApply")
    IPage<Map<String, Object>> listApply(Map<String, String> params, IPage<Map<String, Object>> page);

    //获取进度款申请的工程量清单
    @Select("select * from apply_work_list where apply_id = #{id}")
    List<Map<String, Object>> getWorkList(String id);

    //获取流程id
    @Select("select fid from form  where id=#{id} and target ='apply_progress_payment'")
    String getFid(String id);

    //获取审批流程
    @Select("select fa.*,fn.flowNodeName,su.user_realname from form_audit fa ,flow_node fn ,system_user su where fa.fid=#{fid} and fa.flowNodeId = fn.flowNodeId and fa.eid=su.id")
    List<Map<String, Object>> getfromaudit(String fid);
}
